// 周边配套
<template>
  <div id="SupportDetailsList">
    <Header :currentCity="currentCity" :cityList="cityList"></Header>
    <Crumb :crumbListData="crumbListData"></Crumb>
    <div class="SupportDetailsList_wrap">
      <div class="SupportDetailsList_wrap_tabs">
        <div class="navAcitive">
          <ul>
            <li
              v-for="(item, index) in tabList"
              :key="index"
              :class="{ activeNameTipe: activeCode == index }"
            >
              <a :href="prefixUrl + item.href">{{ item.name }}</a>
            </li>
          </ul>
        </div>
        <div>
          <div id="tabNameAll">
            <div class="PropeIndex6_p1">
              <b>{{ HouseDetail.name }}</b>
              <span
                v-html="
                    HouseDetail.saleStatus == 1
                      ? '在售'
                      : HouseDetail.saleStatus == 2
                      ? '售罄'
                      : '待售'
                  "
              >在售</span>
              <span
                style="color: #ef524d; font-weight: bold; font-size: 16px"
                v-if="HouseDetail.totalPrice && HouseDetail.totalPriceMax"
              >
                参考总价：{{ HouseDetail.totalPrice }}万-{{
                HouseDetail.totalPriceMax
                }}万
              </span>

              <span
                style="color: #ef524d; font-weight: bold; font-size: 16px"
                v-else-if="
                    HouseDetail.totalPrice || HouseDetail.totalPriceMax
                  "
              >参考总价：{{ HouseDetail.totalPrice }}万起</span>

              <span style="color: #ef524d; font-weight: bold; font-size: 16px" v-else>参考总价：价格待定</span>
              <div class="EstateDetail_li1_input EstateDetail_li1house">
                <input type="text" placeholder="请输入您的电话号码" maxlength="11" v-model="phone" />
                <button
                  @click="
                      clickType = 8;
                      subscribe(
                        '咨询返现详情',
                        '专业楼盘管家，深度解答！',
                        'https://mfgj.oss-cn-beijing.aliyuncs.com/upload/20211111/ec7c2095870d43459e3713b406281806.png'
                      );
                    "
                >免费咨询</button>
              </div>
            </div>
            <div class="estatPphoto">
              <div v-for="(item, index) in HouseImgList" :key="index">
                <p v-if="item.count !== 0">{{ item.typeName }}({{ item.count }})</p>
                <li>
                  <span v-for="(its, ind) in item.houseInfoImgs" :key="ind" class="pic cursor">
                    <img
                      :src="its.url"
                      :title="HouseDetail.name + item.typeName"
                      :alt="HouseDetail.name + item.typeName"
                      @click="enlarge(its, item.houseInfoImgs, ind, index)"
                    />
                  </span>
                </li>
              </div>
            </div>
          </div>
          <h4 class="tabNameAll_h4">
            <i class="icon el-icon-warning-outline"></i>
            免责声明：本网站所有楼盘图片均由开发商、经纪人、用户自行提供或上传分享，本站旨在为广大用户免费传递更多信息，本站所有内容仅供参考，请自行核对实际情况，本网站将不对任何内容负法律责任，如对内容有任何疑议，请联系我们,我们将尽快处理。
          </h4>
          <!-- 关键区域，街道，周边 -->
          <keywordBox :currentCity="currentCity" :prefixUrl="prefixUrl" :regionList="regionList"></keywordBox>
        </div>
      </div>
    </div>
    <Footer :currentCity="currentCity"></Footer>

    <!-- 相册图片放大效果 -->
    <div class="AbbrevImgType">
      <el-dialog
        :visible.sync="AbbreviationImgCode"
        :show-close="false"
        width="800px"
        @close="getDialog"
      >
        <div id="swiper_img" class="AbbrevImgType_img">
          <el-carousel
            trigger="click"
            :autoplay="false"
            :loop="false"
            @change="getCarusel"
            height="500px"
            :initial-index="swiper_code"
          >
            <el-carousel-item v-for="(item, index) in swiper_list" :key="index" name="index">
              <img
                :src="item.url"
                :title="HouseDetail.name + item.typeName"
                :alt="HouseDetail.name + item.typeName"
              />
            </el-carousel-item>
          </el-carousel>

          <!-- 缩略图 -->
          <div class="swiper-AbbreviationImg">
            <ul>
              <li
                class="cursor"
                v-for="(item, index) in AbbreviationImg"
                :key="index"
                :class="index == AbbreviationImgClass ? 'AbbrImgClass' : ''"
                @click="getImgList(AbbreviationImg, index)"
              >
                <p>{{ item.typeName }}({{ item.count }})</p>
                <img :src="item.houseInfoImgs[0].url" :title="item.houseInfoImgs[0].url" alt />
              </li>
            </ul>
          </div>
        </div>
        <div class="AbbrevImgType_posi">
          <h5 style="margin: 10px 0">
            <i class="icon el-icon-warning-outline"></i>
            免责声明：本网站所有楼盘图片均由开发商、经纪人、用户自行提供或上传分享，本站旨在为广大用户免费传递更多信息，本站所有内容仅供参考，请自行核对实际情况，本网站将不对任何内容负法律责任，如对内容有任何疑议，请联系我们,我们将尽快处理。
          </h5>
          <p style="float: right">该图片由用户{{ getSwiperDataList }}提供</p>
        </div>
      </el-dialog>
    </div>
    <!-- 弹窗按钮订阅 -->
    <PopupForm
      :show="popupform.show"
      :title="popupform.title"
      :desc="popupform.desc"
      :cover="popupform.cover"
      :phone="popupform.phone"
      :smsState="popupform.smsState"
      :customTheme="popupform.customTheme"
      :background="popupform.background"
      :contentClass="popupform.contentClass"
      @phoneChange="phoneChange"
      @confirm="returnVisit"
      @cancel="
        popupform.show = false;
        popupform.background = '';
      "
    ></PopupForm>
    <!-- 订阅回调弹窗 -->
    <PopupSuccess
      :show="popupsubscribe.show"
      :cover="popupsubscribe.cover"
      :title="popupsubscribe.title"
      :desc="popupsubscribe.desc"
      @cancel="
        popupsubscribe.show = false;
        subscribeDisabled = false;
      "
    ></PopupSuccess>
  </div>
</template>

<script>
var head = {
  title: '成都✖✖✖✖✖✖✖✖✖✖', // 网页包头
  content: '成都✖✖✖✖✖✖✖✖✖✖', // 网页描述
  keywords: '成都,买房,管家,楼盘,买房网,✖✖✖✖✖✖✖✖✖✖', // 网页关键词
}
import u from '~/plugins/Ccom'
export default {
  head() {
    return {
      title: head.title,
      meta: [
        { name: 'description', content: head.content },
        { name: 'keywords', content: head.keywords },
      ],
      link: [
        {
          rel: 'stylesheet',
          href: `/css/lpgk.css?v=${new Date().getTime()}`,
        },
      ],
    }
  },
  data() {
    return {
      activeCode: 2,
      userInfo: '',
      CashBackCode: false, //用户询问
      AbbreviationImgCode: false,
      phone: '',
      swiper_code: 0,
      swiper_list: [],
      getSwiperDataList: '',
      //组件订阅弹窗
      popupsubscribe: {
        show: false, //订阅数据
      },
      customTheme: 0,
      contentClass: '',
      popupform: {
        show: false, //订阅成功数据
        phone: '',
      },
      clickType: '', // 1变价提醒2开盘提醒3咨询剩余房源4订阅楼盘动态5收藏楼盘6户型分析7电话咨询（询购房资格）8询返现9专车看房10咨询返现详情11咨询房贷首付
      subscribeDisabled: false,
    }
  },
  validate(ctx) {
    return /(.*?)\.html/.test(ctx.params.id)
  },
  async asyncData(ctx) {
    var prefixUrl = ctx.prefixUrl //域名
    var currentCity = ctx.currentCity //城市定位
    var cityList = ctx.cityList //
    var crumbListData = [] //栏目信息
    var HouseImgList = [] //楼盘相册数组
    var estateId = ctx.params.id ? ctx.params.id.split('.')[0] : ''
    var tabList = [
      {
        name: '楼盘首页',
        href: `/lpxq/${estateId}.html`,
      },
      {
        name: '基础信息',
        href: `/lpxqxx/${estateId}.html`,
      },
      {
        name: '楼盘相册',
        href: `/lpxqxc/${estateId}.html`,
      },
      {
        name: '楼盘户型',
        href: `/lpxqhx/${estateId}.html`,
      },
      {
        name: '楼盘动态',
        href: `/lpxqdt/${estateId}.html`,
      },
      {
        name: '周边配套',
        href: `/lpxqpt/${estateId}.html`,
      },
      {
        name: '房价走势',
        href: `/lpxqzs/${estateId}.html`,
      },
      {
        name: '你问我答',
        href: `/lpxqwd/${estateId}.html`,
        aliases: 'wenda',
      },
      {
        name: '免费专车',
        href: `/mfzc/${estateId}.html`,
      },
    ]
    var HouseDetail = [] //楼盘详情数据
    var total_code = 0
    var AbbreviationImg = [] //缩略相册图片集
    var swiperData = [] //相册
    var AbbreviationImgClass = 0 //缩略相册图片集active

    // 获取楼盘详情
    var getMetro = await u.http({
      url: '/pc/houseDetail/queryHouseInfoDetailById',
      params: {
        estateId: estateId, //楼盘ID
        userId: '', //用户ID
      },
    })
    if (getMetro.code == 200) {
      let lenNum = 1
      HouseDetail = getMetro.data.houseInfoDetail
      HouseImgList = getMetro.data.imgList
      head.title = `${HouseDetail.name}楼盘效果图、户型图、样板间照片-✖✖✖✖✖✖✖✖✖✖`
      head.content = `✖✖✖✖✖✖✖✖✖✖为您提供${currentCity.cityName}${HouseDetail.name}图片,${HouseDetail.name}样板间装修效果图,楼盘规划图,配套图,实景图,室外图,真实可信的图片信息、清晰详实的实景相册,让您近距离真实的了解${currentCity.cityName}楼盘图。`
      head.keywords = `${HouseDetail.name}楼盘相册`
      // ==========楼盘面包屑============
      var regionCode = {
        title: `${HouseDetail.regionName}楼盘`,
        href: prefixUrl + `/lpcx/${HouseDetail.regionAliases}`,
      }
      // 202112071655 sry 合并路径
      var regionA = [HouseDetail.regionAliases]
      var streetA = [HouseDetail.streetAliases]
      var nowCrumbHref = u.emptyArrayIsNull(regionA.concat(streetA))
      if (HouseDetail.streetName && HouseDetail.streetAliases) {
        var streetCode = {
          title: `${HouseDetail.streetName}楼盘`,
          href: prefixUrl + `/lpcx/${nowCrumbHref.join('-')}`,
        }
      } else {
        var streetCode = null
      }
      var houseCode = {
        title: `${HouseDetail.name}`,
        href: prefixUrl + ctx.route.path,
      }

      // 修改栏目信息
      crumbListData = [
        {
          title: `${currentCity.cityName}✖✖✖✖✖✖✖✖✖✖`,
          href: prefixUrl,
        },
      ]

      if (streetCode) {
        crumbListData.push(regionCode, streetCode, houseCode)
      } else {
        crumbListData.push(regionCode, houseCode)
      }
      HouseImgList.forEach((item, index) => {
        item.houseInfoImgs.forEach((ites) => {
          ites.typeName = item.typeName
          swiperData.push({
            url: ites.url,
            remark: ites.remark,
            typeName: item.typeName,
          })
        })
        if (item.count !== 0) {
          item.current = lenNum
          lenNum += item.count
          AbbreviationImg.push(item)
        }
      })
      // ==========楼盘面包屑============
    } else {
      // 202111091818 sry
      return ctx.redirect('/error.html')
    }

    return {
      tabList,
      prefixUrl,
      currentCity,
      cityList,
      crumbListData,
      estateId,
      total_code,
      HouseDetail,
      HouseImgList,
      AbbreviationImg,
      swiperData,
      AbbreviationImgClass,
      regionList: ctx.regionList
    }
  },
  methods: {
    // 相册放大数据
    enlarge(item, data, index, type) {
      this.AbbreviationImgCode = true
      this.AbbreviationImgList = item
      this.getSwiperDataList = item.remark
      this.swiper_list = data
      this.swiper_code = index
      this.AbbreviationImgClass = type
    },
    getDialog() {
      this.swiper_code = 0
      this.swiper_list = []
    },
    getImgList(AbbreviationImg, type) {
      this.AbbreviationImgClass = type
      this.swiper_list = AbbreviationImg[type].houseInfoImgs
      this.swiper_code = 0
    },
    getCarusel(index) {
      this.swiperData.forEach((item, ins) => {
        if (ins == index - 1) {
          this.getSwiperDataList = item.remark
        }
      })
    },
    // ==========================订阅回访消息==================================
    // 预约
    subscribe(
      title,
      desc,
      cover,
      titleend,
      customTheme,
      background,
      contentClass,
      url
    ) {
      this.popupform.show = true
      this.popupform.title = title
      this.popupform.cover = cover
      this.popupform.smsState = this.smsState
      this.popupform.desc = desc
      if (localStorage.getItem('mobile')) {
        this.popupform.phone = Number(localStorage.getItem('mobile'))
      }
      this.popupsubscribe.title = titleend
      this.popupform.customTheme = customTheme ? Number(customTheme) : 0 //是否为背景验证
      this.popupform.background = background //背景验证背景图
      this.popupform.contentClass = contentClass //活动背景图class样式
      this.popupform.url = url
    },
    // 登录成功回调
    returnVisit() {
      this.popupform.show = false
      this.subscribeDisabled = true
      let url = getCookie('token')
        ? '/app/visitRecord/addVisitRecord'
        : '/app/visitRecord/addVisitRecordByNoToken'
      u.http({
        client: true,
        url,
        headers: {
          token: getCookie('token') || '',
        },
        params: {
          clickType: this.clickType,
          phone: this.popupform.phone,
          estateId: this.estateId,
        },
      }).then((res) => {
        if (this.popupform.url) {
          location.href = this.popupform.url
          return false
        }
        this.popupsubscribe.show = true
      })
    },
    // 监听手机号
    phoneChange(e) {
      this.popupform.phone = e
    },
  },
}
</script>
